草庐IT

python - python unittest中的测试顺序

全部标签

ruby-on-rails - 是否仍然可以在 Rails 4 中使用测试单元?

从Rails3.2升级到Rails4后,我的应用程序可以运行,但是我用测试单元编写的测试是一场灾难。据传,Minitest与测试单元“兼容”。但是,如果我尝试使用(现在捆绑的)Minitest,就会有很多差异——从assert*语句名称和参数到(显然)许多其他既大又微妙的东西。如果我改为尝试避免Minitest并尝试将我的测试单元gem保留在我的Gemfile中,rake测试会爆炸,说,undefinedmethod'refute_predicate'forclass'ActiveSupport::TestCase'这是调用的结果require'rails/test_help':(我已

ruby-on-rails - 如何定期获取/更新 Rails 中的值?

让我们来看一个场景:counter10seconds用户访问了show.html.erb页show.html.erb从database获取值使用.计数器已启动,计数器的每次迭代都是针对10seconds的.在每10seconds之后我想更改@post.value使用utility类。更新@post.value在数据库中。刷新show.html.erb自动和将显示更新后的值以上过程将循环运行,直到用户移动到其他页面。如果我必须在代码中简化问题,那么它会像这样:查看页面Controller方法defshow@post=Post.find(params[:id])enddefupdate..

ruby - class << self 中的类定义是做什么的?

我知道如何添加类方法和类行为usingself(eigenclass).但是,在阅读somesourcecode时,我看到了另一种用法:classLetterAvatarclass这是如何运作的?它有什么作用,什么时候应该使用它?什么是(可能更被认可的)替代方式来写这个? 最佳答案 我认为他们这样做是因为他们在其他任何地方都不需要这个类(class)。如果不打开单例类,流程将如下所示(假设原始代码中元类中定义的每个方法都将以self.为前缀):他们可以将Identity定义为classLetterAvatarclassIdentit

ruby-on-rails - 请求规范中的 stub 身份验证

我正在寻找做this的方法但在要求规范。我需要登录和注销double或instance_double来设计而不是实际的ActiveModel/ActiveRecord。通过使用wiki页面中的代码:moduleRequestSpecHelpersdefsign_in(user=double('user'))ifuser.nil?allow(request.env['warden']).toreceive(:authenticate!).and_throw(:warden,{:scope=>:user})allow(controller).toreceive(:current_user)

ruby - Ruby 中的 [....] 是什么?

这个问题在这里已经有了答案:MethodsinRuby:objectsornot?(6个答案)Whatarerecursivearraysgoodfor?(2个答案)关闭9年前。那天晚上我不小心在Ruby中做了类似的事情:a=*1..5#=>[1,2,3,4,5]a[1,2,3,4,5,[...]]a.last#=>[1,2,3,4,5,[...]]什么是[...],我能用它做什么?

ruby - 如何测试使用 rspec 的 block 的函数

我有一个函数,它接受一个block,打开一个文件,产生并返回:defstart&block.....dosomestuffFile.open("filename","w")do|f|f.write("something")....dosomemorestuffyieldendend我正在尝试使用rspec为其编写测试。我如何stubFile.open以便它将对象f(由我提供)传递给block而不是尝试打开实际文件?像这样的东西:it"shouldtestsomething"domyobject=double("File",{'write'=>true})File.should_rece

ruby - Sinatra,上传表单中的进度条

我正在开发一个Sinatra应用程序,它包含一个上传表单,并带有一个进度条,指示上传完成了多少。该过程,如ryandahl所述,如下:HTTPuploadprogressbarsareratherobfuscated-theytypicallyinvolveaprocessrunningontheserverkeepingtrackofthesizeofthetempfilethattheHTTPserveriswritingto,thenontheclientsideanAJAXcallismadeeverycouplesecondstotheserverduringtheuploa

ruby-on-rails - 文章中的 ActionController::UrlGenerationError#edit

我收到以下错误:没有路由匹配{:action=>"show",:controller=>"articles",:id=>nil}缺少必需的键:[:id]以下是显示错误的代码。这是什么错误,每当我从上一个屏幕点击编辑时,我想我正在发送文章ID。这是我的rake路由输出PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articl

ruby-on-rails - 使用 Devise 登录后测试重定向

为此,我遵循了Devisegithub页面的建议:http://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in现在效果很好,但是您现在如何测试您是否有这种行为? 最佳答案 有两种方法可以在单元级别测试它,一种是在继承应用程序Controller的Controller中编写测试。代码看起来像it"shouldredirecttopage_xafterloggedin"dosign_in:user

ruby - 我如何在 block 之前的 "expect"更改 rspec 中的某些内容?

我有一个这样构造的测试套件:let(:cat){create:blue_russian_cat}subject{cat}context"emptybowl"dolet!(:bowl){create(:big_bowl,amount:0)}before{meow}#atonof`its`or`it`whichrequire`meow`tobeexecutedbeforemakingassertionits(:status){should==:annoyed}its(:tail){should==:straight}#...#hereIwanttoexpectthatnumberofPet